Python Program to check Leap Year | Check whether the given year is leap year or not

Python Program to check Leap Year | Check whether the given year is leap year or not

By using following logic you can check whether a given year is leap or not :

Leap Year:

If a year is divisible by 4, 100 and 400 then it is a leap year.

If a year is divisible by 4 but not divisible by 100 then it is a leap year

Not a Leap Year:

If a year is not divisible by 4 then it is not a leap year

If a year is divisible by 4 and 100 but not divisible by 400 then it is not a leap year


Program to check Leap Year

year = int(input("Enter a year: ")) #enter a year
if (year % 4) == 0:          #condition for normal leap yaer 
   if (year % 100) == 0:     #condition for century year
       if (year % 400) == 0#condition for century leap year
           print("{0} is a leap year".format(year))
       else:
           print("{0} is not a leap year".format(year))
   else:
       print("{0} is a leap year".format(year))
else:
   print("{0} is not a leap year".format(year))

Output:
Enter a year: 2000 2000 is a leap year
Enter a year: 2016
2016 is a leap year
Enter a year: 1993 1993 is not a leap year


Run Code- If you want run this code copy this code, paste here and run.


Best Laptop Under ₹50000/- Must Watch



No comments: